package com.pixiv.service.Impl;

import com.pixiv.DAO.AuditTitleMapping;
import com.pixiv.Entity.AuditTitlePicture;
import com.pixiv.service.AuditTitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class AuditTitleServiceImpl implements AuditTitleService {

    @Autowired
    private AuditTitleMapping auditTitleMapping;

    @Autowired
    JdbcTemplate jdbcTemplate;

    //获得所有正在审核的帖子 同通过lst表输出
    public List<AuditTitlePicture> getAduitTitlePictures()
    {
        List<AuditTitlePicture> list = auditTitleMapping.getAuditTitles();
        return list;
    }

    @Override
    public void insertTempStoragePicture(int id, String fileName, int count) {
        auditTitleMapping.insertTempStoragePicture(id,fileName,count);
    }

    /**
     * 上传审核图
     * @param vars
     */
    @Override
    public void uploadAuditPictureTitle(HashMap<String, Object> vars) {

        String n = String.valueOf(vars.get("UUID"));
        String cap = String.valueOf(vars.get("Caption"));
        String context = String.valueOf(vars.get("Context"));
        String lab = String.valueOf(vars.get("LabelInformation"));
        int age = Integer.valueOf((Integer) vars.get("AgeLimit"));
        int orgin = Integer.valueOf((Integer) vars.get("Orginal"));
        int userID = Integer.valueOf((Integer) vars.get("UserID"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(new Date());
        auditTitleMapping.uploadTitle(n,cap,context,lab,age,orgin,userID,date);
    }

    @Override
    public void switchTempPictureToAudit(int userID) {
    }

    /**
     * 获得审核图片
     * @param uuid
     * @return
     */
    @Override
    public AuditTitlePicture getAuditTitle(String uuid) {
        return auditTitleMapping.getAuditTitle(uuid);
    }

    /**
     * 删除审核帖子
     * @param uuid
     */
    @Override
    public void delAuditTitle(String uuid) {
        auditTitleMapping.delAuditTitle(uuid);
    }
    /**
     * 删除审核的图片
     *
     */
    @Override
    public void delAuditPicture(String uuid) {
        auditTitleMapping.delAuditPictures(uuid);
    }

    /**
     * 上传数据库操作图片字段
     * @param path
     * @param uuid
     * @param location
     */
    @Override
    public void uploadAuditPicture(String path, String uuid, int location) {
        auditTitleMapping.uploadAuditPicture(path,uuid,location);
    }


    @Override
    public String getPicture(String uuid, int location) {
        return auditTitleMapping.getPicture(uuid,location);

    }

    public int getPicturesTotal(String uuid){
        return auditTitleMapping.getPicturesTotal(uuid);
    }

}
